﻿using FlyingEye.Consts;

namespace FlyingEye.Users.Models
{
    public class UserRole
    {
        public string Role { get; }

        public UserRole(string role)
        {
            Role = role;
        }

        public readonly static UserRole Admin = new UserRole(UserRoleConsts.Admin);

        public readonly static UserRole ME = new UserRole(UserRoleConsts.ME);

        public readonly static UserRole PE = new UserRole(UserRoleConsts.PE);

        public readonly static UserRole OPN = new UserRole(UserRoleConsts.OPN);

        public static implicit operator UserRole(UserPermissions permissions)
        {
            return permissions switch
            {
                UserPermissions.Admin => Admin,
                UserPermissions.ME => ME,
                UserPermissions.PE => PE,
                _ => OPN,
            };
        }

        public static implicit operator UserPermissions(UserRole role)
        {
            if (string.Equals(role.Role, Admin.Role, System.StringComparison.OrdinalIgnoreCase))
            {
                return UserPermissions.Admin;
            }
            else
            if (string.Equals(role.Role, ME.Role, System.StringComparison.OrdinalIgnoreCase))
            {
                return UserPermissions.ME;
            }
            else
            if (string.Equals(role.Role, PE.Role, System.StringComparison.OrdinalIgnoreCase))
            {
                return UserPermissions.PE;
            }
            else
            {
                return UserPermissions.OPN;
            }
        }
    }
}
